package com.smart.community.region.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 店铺业主类型枚举
 * 
 * @author Wu.Liang
 * @version 1.0.0
 * @since 2025-09-30
 */
@Getter
@AllArgsConstructor
public enum ShopOwnerTypeEnum {
    
    /**
     * 业主
     */
    OWNER(1, "业主"),
    
    /**
     * 租户
     */
    TENANT(2, "租户");
    
    @JsonValue
    private final Integer code;
    private final String description;
    
    /**
     * Jackson反序列化方法
     * 严格遵循《系统状态枚举权威标准声明.md》规范
     * 
     * @param code 枚举值
     * @return 对应的枚举，如果不存在则返回null
     */
    @JsonCreator
    public static ShopOwnerTypeEnum fromCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (ShopOwnerTypeEnum ownerType : values()) {
            if (ownerType.getCode().equals(code)) {
                return ownerType;
            }
        }
        return null;
    }
    
    /**
     * 根据代码获取描述
     * 
     * @param code 代码
     * @return 描述
     */
    public static String getDescriptionByCode(Integer code) {
        ShopOwnerTypeEnum ownerType = fromCode(code);
        return ownerType != null ? ownerType.getDescription() : "未知类型";
    }
}
